<template>
  <div>
    <div>
        <h3>登录界面</h3><hr>
    </div>
    <el-row type="flex">
        <el-col :span="7"></el-col>
        <el-col :span="8">
            <el-form
                ref="user"
                :model="user"
                label-width="100px">
                <el-form-item label="姓名">
                    <el-input v-model="user.name" placeholder="请输入姓名" clearable></el-input>
                </el-form-item>
                <el-form-item label="密码">
                    <el-input v-model="user.pwd" show-password placeholder="请输入密码"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button size="small" type="warning" @click="checkInfo">登录</el-button>
                    <el-button size="small" type="info" @click="resetForm()">重置</el-button>
                    <!-- <el-button size="small" type="danger" @click="$router.push('/login')">去注册</el-button> -->
                </el-form-item>
            </el-form>
        </el-col>
        <el-col :span="4"></el-col>
    </el-row>
    <!-- <a href="https://gitee.com/oauth/authorize?client_id=5ce37843b772b835323c39254b9c3296640a4e5becdc370f51f5372d308823d9&redirect_uri=http://localhost:8080/project/grade/test&response_type=code">gitee</a> -->
    <!-- <a >gitee</a> -->

  </div>
</template>

<script>
import {mapMutations} from "vuex"
export default {
    data(){
        return{
            user:{
                name:"",
                pwd:"",
            }
        }
    },
    methods:{
        ...mapMutations(["setLoginUser"]),
        resetForm(){
            this.user.name="",
            this.user.pwd=""
        },
        async checkInfo(){
            var tokenData = await this.ajax.postSubmit("/project/users/login",this.user);
            if(tokenData.token.length != 0){
                this.$notify({
                title: '成功',
                message: '登录成功',
                type: 'success',
                duration:500
                });
                // this.setLoginUser(tokenData.token);
                this.$cookies.set("token",tokenData.token);
                this.$cookies.set("refreshToken",tokenData.refreshToken);
                // this.$store.mutations.setLoginUser(loginUser);
                this.$router.push("/index/show");
            }else{
                this.$notify({
                title: '失败',
                message: '密码或账号错误',
                type: 'error',
                duration:2000
                });
            }
        }
    }
}
</script>

<style>

</style>